<?php

	define('ABSOLUTE_SERVER_NAME','http://'.$_SERVER['SERVER_NAME'].'/admin/');
	define('ABSOLUTE_SERVER_DOCUMENT_ROOT','../../../');
	
	ob_start(); 

    if(file_exists('../../../../definitions.inc.php')) include_once('../../../../definitions.inc.php');
    include(ABSOLUTE_SERVER_DOCUMENT_ROOT.'session.inc');
    require_once('invoice_archive.inc');
    //------------------------MODULE LOGS---------------------------
    if (file_exists(ABSOLUTE_SERVER_DOCUMENT_ROOT."modules/logs/logs.inc"))
    require_once(ABSOLUTE_SERVER_DOCUMENT_ROOT.'modules/logs/logs.inc');
    //--------------------------------------------------------------
    require_once(ABSOLUTE_SERVER_DOCUMENT_ROOT.'funct.inc');
    require_once('../../../../classDB.inc.php');
    require_once(ABSOLUTE_SERVER_DOCUMENT_ROOT.'functs.inc');

    if(!GetAdminID($ID)){echo LOGIN_ERR;exit;}
    if(!Right_Check(2)){header('Location:'.ABSOLUTE_SERVER_DOCUMENT_ROOT.'error.php');exit;}

    include ABSOLUTE_SERVER_DOCUMENT_ROOT.'color_style.php';
    include '../../../'.LANGUAGE;
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <?php echo '<meta http-equiv="Content-Type" content="text/html; charset='._CHARSET_.';">'; ?>
	<?php include ABSOLUTE_SERVER_DOCUMENT_ROOT.'html_style.php';?>
</head>
<?php

print "<body bgcolor=\"".Background_Color."\">";


do
{
    $_DB = new classDB();
    if (!$_DB->open()){echo OPEN_DB_ERR; break;}



    $Logged_Admin   =$_SESSION['admin'];
    $index=0;
    $roll_show="/";

    $F_Surname      = $_REQUEST["F_Surname"];
    $F_Organisation = $_REQUEST["F_Organisation"];
    $F_ICO          = $_REQUEST["F_ICO"];
    $Orders_Year	= $_REQUEST["Orders_Year"];
    
    
    //------------------------------------------------------------------------
    //ak nie je zadane inak, tak je vybrany defaultne aktualny rok zobrazenia arch. objednavok
    if ($Orders_Year=="") $Orders_Year=date("Y");
    //------------------------------------------------------------------------


	//------------------------------------------------------------------------
	//-------------------Formular na vyber roku archivu-----------------------
	Print_Form_For_Year_Select($Orders_Year);
	//------------------------------------------------------------------------
	
	
	//------------------------------------------------------------------------
	//-------------------Test, ci je hodnota rok cislo------------------------
	if (!(is_numeric($Orders_Year) and is_numeric($Orders_Year[strlen($Orders_Year)-1]) and $Orders_Year!="")){
        print  "<script language=\"JavaScript\">
	        		<!--
	                window.alert(\"".INV_ZADANA_HODNOTA_ROKU.": '".$Orders_Year."' ".INV_NIE_JE_CISLO."\");
	        		//-->
            	</script>
		";
		break;
	}
    //-----------------------------------------------------------------------
	
	
    $events=$_REQUEST["events"];
    switch($events) {
           case 'delete_order':{
                     if ($_REQUEST["GrantDelete"]!="YES")
                    	print"
                        		<center>
                                    <table border=\"1\" bgcolor=\"".BACKGROUND_IN_TABLE."\">
                                        <tr>
                                            <td>
                                                ".INV_NAOZAJ_ODSTRANIT."
                                                <center>
                                                <form action=\"invoice_archive.php\" target=\"place\" method=\"post\">
                                                    <input type=\"hidden\" value=\"".$Orders_Year."\" name=\"Orders_Year\" />
                                                    <input type=\"hidden\" value=\"".$ActualQvantumPage."\" name=\"ActualQvantumPage\" />
                                                    <input type=\"hidden\" name=\"events\" value=\"delete_order\" />
                                                    <input type=\"hidden\" name=\"Ch_ID\" value=\"".$_REQUEST["Ch_ID"]."\" />
                                                    <input type=\"hidden\" name=\"PageNo\" value=\"".$PageNo."\" />
                                                    <input type=\"hidden\" name=\"GrantDelete\" value=\"YES\" />
                                                    <input type=\"hidden\" value=\"".$F_Surname."\" name=\"F_Surname\" />
                                                    <input type=\"hidden\" value=\"".$F_Organisation."\" name=\"F_Organisation\" />
                                                    <input type=\"hidden\" value=\"".$F_ICO."\" name=\"F_ICO\" />
                                                    <input type=\"submit\" value='".INV_ANO_VYMAZAT."' style=\"width :100px; background-color: ".BUTTON_ON_OUT.";\"
                                                        onmouseover=\"this.style.backgroundColor='".BTN_IN_TABLE."'; this.style.fontWeight='bold';\";
                                                        onmouseout=\"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal';\" 
                                                    />
                                                </form>
                                                </center>
                                                <center>
                                                <form action=\"invoice_archive.php\" target=\"place\" method=\"post\">
                                                	<input type=\"hidden\" value=\"".$Orders_Year."\" name=\"Orders_Year\" />
                                                    <input type=\"hidden\" value=\"".$ActualQvantumPage."\" name=\"ActualQvantumPage\" />
                                                    <input type=\"hidden\" name=\"events\" value=\"show_order\" />
                                                    <input type=\"hidden\" name=\"Ch_ID\" value=\"".$_REQUEST["Ch_ID"]."\" />
                                                    <input type=\"hidden\" name=\"PageNo\" value=\"".$PageNo."\" />
                                                    <input type=\"hidden\" value=\"".$F_Surname."\" name=\"F_Surname\" />
                                                    <input type=\"hidden\" value=\"".$F_Organisation."\" name=\"F_Organisation\" />
                                                    <input type=\"hidden\" value=\"".$F_ICO."\" name=\"F_ICO\" />
                                                    <input type=\"submit\" value='".INV_NIE_STORNO."' style=\"width :100px; background-color: ".BUTTON_ON_OUT.";\"
                                                        onmouseover=\"this.style.backgroundColor='".BTN_IN_TABLE."'; this.style.fontWeight='bold';\";
                                                        onmouseout=\"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal';\" 
                                                    />
                                                </form>
                                                </center>
                                            </td>
                                        </tr>
                                    </table>
                                </center>
                            ";
                        else{
                            //SQL_Delete_Invoice_From_Archive($_REQUEST["Ch_ID"]);										
                            $sql="DELETE FROM invoice_heads_archive WHERE ID=".$_REQUEST["Ch_ID"];
                            mysql_query($sql);
                            $sql="DELETE FROM invoice_products_archive WHERE IHA_ID=".$_REQUEST["Ch_ID"];
                            mysql_query($sql);
                            //Log_Insert("Vymazana faktura-archiv", $_REQUEST["Ch_ID"], $ID);
                        }
                        break;
                    }
           case 'show_order':       $roll_show = rutine_menu($_REQUEST["roll_show"],$_REQUEST["Ch_ID"]);
                                    break;
           default:break;
    }

    print("<center><b>".INV_ARCHIV_FAKTUR."</b></center>");

    //**************************************************************************
    //
    //Zobrazenie komponentov pre vyhladavanie
    //
    //**************************************************************************

    if ($F_Surname=="" and $F_Organisation=="" and $F_ICO=="")
            print"
                    <center>
                    <table style=\"border:1px solid black;\">
                        <tr>
                            <td>
                                <form action=\"invoice_archive.php\" target=\"place\" method=\"post\">
                                    ".INV_PRIEZVISKO.":
                                    <input type=\"text\" name=\"F_Surname\" />
                                    <input type=\"hidden\" value=\"".$Orders_Year."\" name=\"Orders_Year\" />
                                    <input type=\"submit\" value=\"".INV_VYHLADAT."\" style=\"width :70px; background-color: ".BUTTON_ON_OUT.";\"
                                        onmouseover=\"this.style.backgroundColor='".BUTTON_ON_OVER."'; this.style.fontWeight='bold';\";
                                        onmouseout=\"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal';\" />
                                </form>
                            </td>
                            <td>
                                <form action=\"invoice_archive.php\" target=\"place\" method=\"post\">
                                    ".INV_ORGANIZaCIA.":
                                    <input type=\"text\" name=\"F_Organisation\" />
                                    <input type=\"hidden\" value=\"".$Orders_Year."\" name=\"Orders_Year\" />
                                    <input type=\"submit\" value=\"".INV_VYHLADAT."\" style=\"width :70px; background-color: ".BUTTON_ON_OUT.";\"
                                        onmouseover=\"this.style.backgroundColor='".BUTTON_ON_OVER."'; this.style.fontWeight='bold';\";
                                        onmouseout=\"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal';\" />
                                </form>
                            </td>
                            <td>
                                <form action=\"invoice_archive.php\" target=\"place\" method=\"post\">
                                    ".INV_ICO.":
                                    <input type=\"text\" name=\"F_ICO\" />
                                    <input type=\"hidden\" value=\"".$Orders_Year."\" name=\"Orders_Year\" />
                                    <input type=\"submit\" value=\"".INV_VYHLADAT."\" style=\"width :70px; background-color: ".BUTTON_ON_OUT.";\"
                                        onmouseover=\"this.style.backgroundColor='".BUTTON_ON_OVER."'; this.style.fontWeight='bold';\";
                                        onmouseout=\"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal';\" />
                                </form>
                            </td>
                        </tr>
                    </table>
                        </center>
			";
        else
            print"
                <center>
                <table style=\"border=1px solid black;\">
                    <tr>
                        <td>
                            <form action=\"invoice_archive.php\" target=\"place\" method=\"post\">
                            	<input type=\"hidden\" value=\"".$Orders_Year."\" name=\"Orders_Year\" />
                                <input type=\"submit\" value=\"".INV_ZRUSIT_VYHLADAVANIE_ZOBRAZIT_VSETKY_ZAZNAMY."\" style=\"width=280px; background-color: ".BUTTON_ON_OUT.";\"
                                    onmouseover=\"this.style.backgroundColor='".BUTTON_ON_OVER."'; this.style.fontWeight='bold';\";
                                    onmouseout=\"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal';\" />
                            </form>
                        </td>
                    </tr>
                </table>
                </center>";
    print "<br>";
    
    //----------------------------------------------------------------------------------
    //-----------------------------Vytvorenie podstranok--------------------------------
    include 'paging_invoice_archive.inc';
    //----------------------------------------------------------------------------------
    
    //**************************************************************************
    //
    //Naplneneie obsahu stranky datami z databazy
    //
    //**************************************************************************
    //if($Category_ID==""){mysql_close(); break;}
        $From   = $PageNo*$ItemsOnPage;
        if($From<0) $From=0;

        if ($F_Surname!="") $sql_psel= "SELECT * FROM invoce_heads_archive WHERE ((YEAR(IHA_Create)=$Orders_Year) AND (IHA_Surname LIKE '%".$F_Surname."%')) ORDER BY IHA_Create DESC LIMIT ".$From.",".$ItemsOnPage;
        if ($F_Organisation!="") $sql_psel= "SELECT * FROM invoce_heads_archive WHERE ((YEAR(IHA_Create)=$Orders_Year) AND (IHA_Organisation LIKE '%".$F_Organisation."%)) 'ORDER BY IHA_Create DESC LIMIT ".$From.",".$ItemsOnPage;
        if ($F_ICO!="") $sql_psel= "SELECT * FROM invoce_heads_archive WHERE ((YEAR(IHA_Create)=$Orders_Year) AND (IHA_ICO='".$F_ICO."')) ORDER BY IHA_Create DESC LIMIT ".$From.",".$ItemsOnPage;
        if ($F_Surname=="" and $F_Organisation=="" and $F_ICO=="") $sql_psel=  "SELECT * FROM invoice_heads_archive WHERE YEAR(IHA_Create)=$Orders_Year ORDER BY IHA_Create DESC LIMIT ".$From.",".$ItemsOnPage;

        $Product_source = mysql_query($sql_psel);
        $counter=0;
        while($sql_array_adm = mysql_fetch_object($Product_source))
        {
            $ShowAsDetails = is_roll($roll_show,$sql_array_adm->ID);
            if(!$ShowAsDetails)
            {
                    if(($counter%2))
                        print "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"98%\" bgcolor=\"".TR_BACKGOUND_COLOR_2."\">";
                    else
                        print "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"98%\" bgcolor=\"".TR_BACKGOUND_COLOR_1."\">";

                    
                    print "<tr><td>";
                        if(($counter%2))
                            print "<table  border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" bgcolor=\"".TR_BACKGOUND_COLOR_2."\"><tr>";
                        else
                            print "<table  border=\"0\"cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" bgcolor=\"".TR_BACKGOUND_COLOR_1."\"><tr>";

                    print "<td align=\"left\">";
                      print("<b><font color=\"black\">".$sql_array_adm->IHA_Prefix.$sql_array_adm->IHA_No."</font color></b>");
                    print "</td>";
                    print "<td align=\"right\">";
                      print("<b><font color=\"".TEXT_COLOR_ORDER."\">(".$sql_array_adm->IHA_Organisation." ".$sql_array_adm->IHA_Name." ".$sql_array_adm->IHA_Surname.")</font color></b>");
                      print " (".date(sttngs_DATE_FORMAT,strtotime($sql_array_adm->IHA_Create)).")";
                    print "</td>";
                    print "</tr></table></td>";

                    print "<td align=\"right\" width=\"63px\">";
                          print "<form action=\"invoice_archive.php\" target=\"place\" method=\"post\">";
                          	print "<input type=\"hidden\" value=\"".$Orders_Year."\" name=\"Orders_Year\" />";
                            print "<input type=\"hidden\" value=\"".$ActualQvantumPage."\" name=\"ActualQvantumPage\" />";
                            print "<input type=\"hidden\" name=\"events\" value=\"show_order\" />";
                            print "<input type=\"hidden\" name=\"roll_show\" value=\"".$roll_show."\" />";
                            print "<input type=\"hidden\" name=\"Ch_ID\" value=\"".$sql_array_adm->ID."\" />";
                            print "<input type=\"hidden\" name=\"PageNo\" value=\"".$PageNo."\" />";
                            print "<input type=\"hidden\" value=\"".$F_Surname."\" name=\"F_Surname\" />";
                            print "<input type=\"hidden\" value=\"".$F_Organisation."\" name=\"F_Organisation\" />";
                            print "<input type=\"hidden\" value=\"".$F_ICO."\" name=\"F_ICO\" />";
                            print "<input type=\"submit\" value=\"".INV_ZOBRAZIT."\" style=\"width :60px; background-color: ".BUTTON_ON_OUT.";\"
                            onmouseover=\"this.style.backgroundColor='".BUTTON_ON_OVER."'; this.style.fontWeight='bold';\";
                            onmouseout=\"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal';\" />";
                          print "</form>";
                    print "</td>";

                    print "<td align=\"right\" width=\"43px\">";
                          print "<form action=\"invoice_archive_print.php\" target=\"_Blank\" method=\"post\">";
                          	print "<input type=\"hidden\" value=\"".$Orders_Year."\" name=\"Orders_Year\" />";
                            print "<input type=\"hidden\" name=\"ID\" value=\"".$sql_array_adm->ID."\" />";
                            print "<input type=\"hidden\" value=\"".$F_Surname."\" name=\"F_Surname\">";
                            print "<input type=\"hidden\" value=\"".$F_Organisation."\" NAME=\"F_Organisation\" />";
                            print "<input type=\"hidden\" value=\"".$F_ICO."\" name=\"F_ICO\" />";
                            print "<input type=\"submit\" value=\"".INV_TLAC."\" style=\"width :40px; background-color: ".BUTTON_ON_OUT.";\"
                            onmouseover=\"this.style.backgroundColor='".BUTTON_ON_OVER."'; this.style.fontWeight='bold';\";
                            onmouseout=\"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal';\" />";
                          print "</form>";
                    print "</td>";

                    print "<td align=\"right\" width=\"63px\">";
                          print "<form action=\"invoice_archive.php\" target=\"place\" method=\"post\">";
                          	print "<input type=\"hidden\" value=\"".$Orders_Year."\" name=\"Orders_Year\" />";
                          	print "<input type=\"hidden\" value=\"".$ActualQvantumPage."\" NAME=\"ActualQvantumPage\" />";
                            print "<input type=\"hidden\" name=\"events\" value=\"delete_order\" />";
                            print "<input type=\"hidden\" name=\"roll_show\" value=\"".$roll_show."\" />";
                            print "<input type=\"hidden\" name=\"Ch_ID\" value=\"".$sql_array_adm->ID."\" />";
                            print "<input type=\"hidden\" name=\"PageNo\" value=\"".$PageNo."\" />";
                            print "<input type=\"hidden\" value=\"".$F_Surname."\" name=\"F_Surname\" />";
                            print "<input type=\"hidden\" value=\"".$F_Organisation."\" name=\"F_Organisation\" />";
                            print "<input type=\"hidden\" value=\"".$F_ICO."\" name=\"F_ICO\" />";
                            print "<input type=\"submit\" value=\"".INV_ODSTRANIT."\" style=\"width :60px; background-color: ".BUTTON_ON_OUT.";\"
                            onmouseover=\"this.style.backgroundColor='".BUTTON_ON_OVER."'; this.style.fontWeight='bold';\";
                            onmouseout=\"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal';\" />";
                          print "</form>";
                    print "</td></tr>";

            }
            else
            {
                if($ShowAsDetails){
                    if(($counter%2))
                        print "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"98%\" bgcolor=\"".TR_BACKGOUND_COLOR_2."\">";
                    else
                        print "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"98%\" bgcolor=\"".TR_BACKGOUND_COLOR_1."\">";

                    print "<tr><td>";


                    //***********zobrazenie mena, priezviska, nick, prav********  
                    if(($counter%2))
                        print "<table  border=\"1\" cellpadding=\"0\" cellspacing=\"0\" bgcolor=\"".TR_BACKGOUND_COLOR_2."\" width=\"800px\" style=\"margin-left:5pt;\">";
                    else
                        print "<table  border=\"1\" cellpadding=\"0\" cellspacing=\"0\" bgcolor=\"".TR_BACKGOUND_COLOR_1."\" width=\"800px\" style=\"margin-left:5pt;\">";


                                @$dbResult=mysql_query("SELECT * FROM invoice_heads_archive WHERE ID=".$sql_array_adm->ID);
                                if (!dbResult) {
                                    print INV_CHYBA_PRI_VYHLADAVANI_UDAJOV_STRANKU_NEMOZNO_ZOBRAZIT;
                                    break;
                                }
                                $sql_array_User = mysql_fetch_object($dbResult);
                                //**********************************************************************
                                //zobrazenie udajov o dodavatelovi
                                //**********************************************************************
                                print "<tr><td valign=\"top\">";
                                    print ("<b><u>".INV_DODAVATEL.":</u></b><br />");
                                    $file = fopen(ABSOLUTE_SERVER_DOCUMENT_ROOT."address.txt", "r") or die (INV_CHYBA_SUBORU." 'address.txt'!");
                                    while (!feof($file)){
                                            $file_row = fgets($file, 500);
                                            print ($file_row. "<br />");
                                    }
                                    
                                    //sposob dorucenia
                                    print "<br /><br />".INV_SPOSOB_DORUCENIA.":".$sql_array_User->IHA_Delivery;
					                                    
                                print "</td>";
                                //**********************************************************************
                                //zobrazenie hlavicky faktury a udajov o odberatelovi
                                //**********************************************************************
                                print "<td valign=\"top\">";
                                	print "<table style=\"width:100%;\">";
                                                        print "<tr style=\"border:1px solid black;\">";
                                                                print "<td style=\"border:1px solid black;\">";
                                                                        print "
                                                                                <table>
                                                                                        <tr>
                                                                                                <td>
                                                                                                        ".INV_FAKTURA_CISLO.":
                                                                                                </td>
                                                                                                <td>
                                                                                                        ".$sql_array_User->IHA_Prefix.$sql_array_User->IHA_No."
                                                                                                </td>
                                                                                        <tr>
                                                                                        </tr>
                                                                                                <td>
                                                                                                        ".INV_KONSTANTNY_SYMBOL.":
                                                                                                </td>
                                                                                                <td>
                                                                                                        ".$sql_array_User->IHA_Constant_Symbol."
                                                                                                </td>
                                                                                        </tr>
                                                                                </table>
                                                                        ";
                                                                print "</td>"; 
                                                        print "</tr>";
                                                        print "<tr>";
                                                                print "<td>";                                	
			                                    print "<b><u>".INV_ODBERATEL.":</u></b>";
							if ($sql_array_User->IHA_ICO!="")
		                                            print "(".INV_ICO.": ".$sql_array_User->IHA_ICO.")<br />";
		                                        else
                                                            print "<br />";
		                                        //vyhladanie udajov v DB
		                                        if ($sql_array_User->IHA_Organisation!="")
		                                            print $sql_array_User->IHA_Organisation."<br />";
		                                        if ($sql_array_User->IHA_Organisation=="")
		                                        	print $sql_array_User->IHA_Name." ".$sql_array_User->IHA_Surname."<br />";
		                                        print $sql_array_User->IHA_Street."<br />";
		                                        print $sql_array_User->IHA_PostID." ".$sql_array_User->IHA_City."<br />";		                                        
		                                        if ($sql_array_User->IHA_DIC!="")
		                                            print INV_DIC.": ".$sql_array_User->IHA_DIC."<br />";
		                                        $Order_text = $sql_array_User->IHA_Additorial_Text;
		                                        mysql_free_result($dbResult);
		                            		print "</td>"; 
                                                    print "</tr>"; 
                                                    print "<tr style=\"border:1px solid black;\">";
                                                            print "<td style=\"border:1px solid black;\">";
                                                                    print "
                                                                            <table>
                                                                                    <tr>
                                                                                            <td>
                                                                                                   ".INV_DATUM_VYSTAVENIA.":
                                                                                            </td>														
                                                                                            <td>  
                                                                                                    ".date(sttngs_DATE_FORMAT,strtotime($sql_array_User->IHA_Create))."
                                                                                            </td>
                                                                                    </tr>
                                                                                    <tr>
                                                                                            <td>
                                                                                                    ".INV_DATUM_SPLATNOSTI.":
                                                                                            </td>
                                                                                            <td>  
                                                                                                    ".date(sttngs_DATE_FORMAT,strtotime($sql_array_User->IHA_Expiration))."
                                                                                            </td>
                                                                                    </tr>
                                                                                    <tr>
                                                                                            <td>
                                                                                                    ".INV_DATUM_DAN.":
                                                                                            </td>
                                                                                            <td>  
                                                                                                    ".date(sttngs_DATE_FORMAT,strtotime($sql_array_User->IHA_Tax))." 
                                                                                            </td>
                                                                                    </tr>
                                                                                    <tr>
                                                                                            <td>
                                                                                                    ".INV_SPOSOB_PLATBY.":
                                                                                            </td>
                                                                                            <td>  
                                                                                                    ".$sql_array_User->IHA_Payment_Type."
                                                                                            </td>
                                                                                    </tr>
                                                                            </table>
                                                                    ";
                                                            print "</td>"; 
                                                    print "</tr>";          
		                            print "</table>";
                                print "</td></tr>";
                                //**********************************************************************
                                //zobrazenie tovaru
                                //**********************************************************************
                                print "<tr><td colspan=\"2\">";
                                    print ("<b><u>".INV_FAKTURUJEME_VAM_ZA.":</u></b></br>");
                                print "</td></tr>";
                                print "<tr><td colspan=\"2\">";
                                print "<table width=\"100%\">";
                                
                                if(PAYER_VAT=="YES")
                                    //**********************************************************************
                                    //platca DPH
                                    print "<tr><td><b>".O_KOD."</b></td><td><b>".O_POLOZKA."</b></td><td><b>".O_MJ."</b></td><td><b>".O_CENA_ZA_MJ."</b></td><td><b>".O_DPH."</b></td><td><b>".O_CENA_S_DPH."</b></td><td><b>".O_MNOZSTVO."</b></td><td><b>".O_SPOLU."</b></td></tr>";
                                    //**********************************************************************
                                    else
                                    //**********************************************************************
                                    //platca DPH
                                    print "<tr><td><b>".O_KOD."</b></td><td><b>".O_POLOZKA."</b></td><td><b>".O_MJ."</b></td><td><b>".O_CENA_ZA_MJ."</b></td><td><b>".O_MNOZSTVO."</b></td><td><b>".O_SPOLU."</b></td></tr>";
                                    //**********************************************************************

                        $sql_bin= "SELECT * FROM invoice_products_archive WHERE IHA_ID=".$sql_array_adm->ID;
                        $bin_source = mysql_query($sql_bin);
                        $TotalSum=0;
                        $TotalEuro=0;
                        while ($sql_array_Prodct = mysql_fetch_object($bin_source))
                        {                          
                                //urcenie ci sa produt nachadza v tabulke produktov
                                if($sql_array_Prodct->IPA_ID != "")
                                        $products_count = mysql_fetch_row(mysql_query("SELECT COUNT(*) FROM products WHERE ID=$sql_array_Prodct->IPA_ID"));    
                                else
                                        $products_count[0] = 0;
                          		
                                print "<tr><td>";              
                                        //zobrazenie produktu v objednavke
                                        if($products_count[0] < 1)
                                            print $sql_array_Prodct->IPA_Code;
                                	else
                                            //odkaz na produkt v objednavke										
                                            print "
                                                <a href=\"".ABSOLUTE_SERVER_NAME."show_product_detail.php?ID=".$sql_array_Prodct->IPA_ID."&amp;Count=1 \" 
                                                    target=\"oa_product_detail\">".$sql_array_Prodct->IPA_Code."
                                                </a>
                                            ";
										
                                print "</td>";
                                print "<td>";
                                        //zobrazenie produktu v objednavke
                                        if($products_count[0] < 1)
                                            print $sql_array_Prodct->IPA_Name;
                                	else
                                            //odkaz na produkt v objednavke
                                            print "
                                                <a href=\"".ABSOLUTE_SERVER_NAME."show_product_detail.php?ID=".$sql_array_Prodct->IPA_ID."&amp;Count=1 \" 
                                                   target=\"oa_product_detail\">".$sql_array_Prodct->IPA_Name."
                                                </a>
                                            ";
                                print "</td>";
                                print "<td>";
                                print $sql_array_Prodct->IPA_UnitType;
                                print "</td>";
                                print "<td>";
                                print FormatItAsCurrency($sql_array_Prodct->IPA_Price);
                                if (file_exists("../../../euro.php")) print O_MENA." <br />".FormatItAsCurrency($sql_array_Prodct->IPA_Euro).O_SKK_MENA;
                                print "</td>";
                                    if(PAYER_VAT=="YES"){
                                        //**********************************************************************
                                        //platca DPH
	                                print "<td>";
	                                print $sql_array_Prodct->IPA_DPH." %";
	                                print "</td>";
	                                print "<td>";
	                                print FormatItAsCurrency(((($sql_array_Prodct->IPA_DPH)/100)+1) * $sql_array_Prodct->IPA_Price);
	                                if (file_exists("../../../euro.php")) O_MENA."<br />".FormatItAsCurrency(((($sql_array_Prodct->IPA_DPH)/100)+1) * $sql_array_Prodct->IPA_Euro).O_SKK_MENA;
	                                print "</td>";
	                            }
                                print "<td>";
                                print $sql_array_Prodct->IPA_Count;
                                print "</td>";
                                print "<td>";
                                if(PAYER_VAT=="YES"){
                                        //**********************************************************************
                                        //platca DPH
                                	print FormatItAsCurrency(((($sql_array_Prodct->IPA_DPH)/100)+1) * $sql_array_Prodct->IPA_Price * $sql_array_Prodct->IPA_Count);
                                	if (file_exists("../../../euro.php")) print O_MENA."<br />".FormatItAsCurrency(((($sql_array_Prodct->IPA_DPH)/100)+1) * $sql_array_Prodct->IPA_Euro * $sql_array_Prodct->IPA_Count).O_SKK_MENA;
                                }
                                else{
                                	//neplatca
                                	print FormatItAsCurrency($sql_array_Prodct->IPA_Price * $sql_array_Prodct->IPA_Count);
                                	if (file_exists("../../../euro.php")) print O_MENA."<br />".FormatItAsCurrency($sql_array_Prodct->IPA_Euro * $sql_array_Prodct->IPA_Count).O_SKK_MENA;
                                }
                                print "</td></tr>";
                                
                                if(PAYER_VAT=="YES"){
							        //**********************************************************************
							        //platca DPH
                                	$TotalSum+=((($sql_array_Prodct->IPA_DPH)/100)+1) * $sql_array_Prodct->IPA_Price * $sql_array_Prodct->IPA_Count;
                                	if (file_exists("../../../euro.php")) $TotalEuro+=((($sql_array_Prodct->IPA_DPH)/100)+1) * $sql_array_Prodct->IPA_Euro * $sql_array_Prodct->IPA_Count;
                                }
                                else{
                                	//neplatca DPH
                                	$TotalSum+=$sql_array_Prodct->IPA_Price * $sql_array_Prodct->IPA_Count;
                                	if (file_exists("../../../euro.php")) $TotalEuro+= $sql_array_Prodct->IPA_Euro * $sql_array_Prodct->IPA_Count;
                                }
                        }


                                print "</table>";
                                print "</td></tr>";
                                //**********************************************************************
                                //zobrazenie celkovej sumy
                                //**********************************************************************
                                print "
                                        <tr>
                                                <td style=\"text-align:left; width:250px;\">
                                                        <br />
                                                        $Order_text
                                                        <br />
                                                </td>
                                                <td style=\"text-align:right;\">
                                ";
                                if(PAYER_VAT=="YES"){
                                        //**********************************************************************
                                        //platca DPH
                                        print ("<br /><b><u>".O_CELKOM.":".RoundIt($TotalSum).O_MENA_S_DPH."</u></b><br /><br />");
                                        if (file_exists("../../../euro.php")) print (RoundItEUR($TotalEuro).O_SKK_MENA_S_DPH."<br />");
                                }
                                else{
                                        //neplatca DPH
                                        print "<br /><b><u>".O_CELKOM.":".RoundIt($TotalSum).O_MENA."</u></b><br />";
                                        if (file_exists("../../../euro.php")) print RoundItEUR($TotalEuro).O_SKK_MENA."<br />";
                                        print O_NIE_SME_PLATCOVIA_DPH."<br />";	
                                }
                                print "
                                                </td>
                                        </tr>
                                </table>
                                ";


                    //print "</table>";
                    //**********************************************************

                    print "</td><tr>";

                    print "<tr><td>";
                    	print "<br />";
                    	print "<table></tr>";
		                    print "<td align=\"right\" valign=\"bottom\" width=\"43px\">";
		                          print "<form action=\"invoice_archive_print.php\" target=\"_Blank\" method=\"post\">";
		                          	print "<input type=\"hidden\" value=\"".$Orders_Year."\" name=\"Orders_Year\" />";
		                            print "<input type=\"hidden\" name=\"ID\" value=\"".$sql_array_adm->ID."\" />";//$sql_array_adm->Original_ID
		                            print "<input type=\"hidden\" value=\"".$F_Surname."\" name=\"F_Surname\">";
		                            print "<input type=\"hidden\" value=\"".$F_Organisation."\" name=\"F_Organisation\" />";
		                            print "<input type=\"hidden\" value=\"".$F_ICO."\" name=\"F_ICO\" />";
		                            print "<input type=\"submit\" value=\"".INV_TLAC."\" style=\"width :40px; background-color: ".BUTTON_ON_OUT.";\"
		                            onmouseover=\"this.style.backgroundColor='".BUTTON_ON_OVER."'; this.style.fontWeight='bold';\";
		                            onmouseout=\"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal';\" />";
		                          print "</form>";
		                    print "</td>";
		                    
		                    print "<td align=\"right\" valign=\"bottom\" width=\"83px\">";
		                          print "<form action=\"invoice_archive.php\" target=\"place\" method=\"post\">";
		                          	print "<input type=\"hidden\" value=\"".$Orders_Year."\" name=\"Orders_Year\" />";
		                          	print "<input type=\"hidden\" value=\"".$ActualQvantumPage."\" name=\"ActualQvantumPage\" />";
		                            print "<input type=\"hidden\" name=\"events\" value=\"show_order\" />";
		                            print "<input type=\"hidden\" name=\"roll_show\" value=\"".$roll_show."\" />";
		                            print "<input type=\"hidden\" name=\"Ch_ID\" value=\"".$sql_array_adm->ID."\" />";
		                            print "<input type=\"hidden\" name=\"PageNo\" value=\"".$PageNo."\" />";
		                            print "<input type=\"hidden\" value=\"".$F_Surname."\" name=\"F_Surname\" />";
		                            print "<input type=\"hidden\" value=\"".$F_Organisation."\" name=\"F_Organisation\" />";
		                            print "<input type=\"hidden\" value=\"".$F_ICO."\" name=\"F_ICO\" />";
		                            print "<input type=\"submit\" value=\"".INV_ZRUSIT_NAHLAD."\" style=\"width :120px; background-color: ".BUTTON_ON_OUT.";\"
		                            onmouseover=\"this.style.backgroundColor='".BUTTON_ON_OVER."'; this.style.fontWeight='bold';\";
		                            onmouseout=\"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal';\" />";
		                          print "</form>";
		                    print "</td></tr>";
		                print "</tr></table>";

                    print "</table>";
                };
            }
            print "</table>";
            $counter++;
        }


        print "<br>";
        PrintLine();

    //----------------------------------------------------------------------------------
    //-----------------------------Vytvorenie podstranok--------------------------------
    include 'paging_invoice_archive.inc';
    //----------------------------------------------------------------------------------

    mysql_close();
}
while(false)
?>


</body>
</html>
